
<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">
    <title>留言板V1.0</title>

    <!-- Bootstrap core CSS -->
    <link href="./template/css/bootstrap.min.css" rel="stylesheet">
    <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
  </head>

  <body>

    <nav class="navbar navbar-inverse navbar-fixed-top">
      <div class="container">
        <div class="navbar-header">
          <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
          <a class="navbar-brand" href="#">留言板V1.0</a>
        </div>
        <div id="navbar" class="navbar-collapse collapse">
          <form class="navbar-form navbar-right">
            <div class="form-group">
              <input type="text" placeholder="Email" class="form-control">
            </div>
            <div class="form-group">
              <input type="password" placeholder="Password" class="form-control">
            </div>
            <button type="submit" class="btn btn-success">登录</button>
            <a href="./register.php" class="btn btn-success">注册</a>
          </form>
        </div><!--/.navbar-collapse -->
      </div>
    </nav>

    <!-- Main jumbotron for a primary marketing message or call to action -->
    <div class="jumbotron">
    </div>

    <style>
      
      .info{
        color: green;
      }
      .red{
        color: red;
      }
    </style>

    <div class="container">
      <div class="row" style="padding-top: 20px;">
      	 <form class="form-horizontal" action="./index.php?c=User&a=add" method="post" id="register">
          <div class="form-group">
            <label for="inputEmail3" class="col-sm-2 control-label">用户名</label>
            <div class="col-sm-4">
              <input type="text" class="form-control"  name="username" value="xuebing" placeholder="用户名">
            </div>
            <div class="col-sm-4 info"></div>
          </div>
          <div class="form-group">
            <label for="inputEmail3" class="col-sm-2 control-label">邮箱</label>
            <div class="col-sm-4">
              <input type="email" class="form-control"  placeholder="邮箱" value="113@qq.com" name="email">
            </div>
            <div class="col-sm-4 info">
            </div>
          </div>
          <div class="form-group">
            <label for="inputEmail3" class="col-sm-2 control-label">手机</label>
            <div class="col-sm-4">
              <input type="text" value="18925139194" class="form-control"  name="phone" placeholder="手机">
            </div>
            <div class="col-sm-4 info">
            </div>
          </div>
          <div class="form-group">
            <label for="inputPassword3" class="col-sm-2 control-label">密码</label>
            <div class="col-sm-4">
              <input type="password" class="form-control"  placeholder="密码" value="123456" name="password">
            </div>
            <div class="col-sm-4 info">
            </div>
          </div>
          <div class="form-group">
            <label for="inputPassword3" class="col-sm-2 control-label">确认密码</label>
            <div class="col-sm-4">
              <input type="password" class="form-control"  placeholder="确认密码" value="123456" name="repassword">
            </div>
            <div class="col-sm-4 info">
            </div>
          </div>
          <div class="form-group">
            <div class="col-sm-offset-2 col-sm-10">
              <button type="submit" id="btn" disabled="" class="btn btn-success">注册</button>
            </div>
          </div>
        </form>
      </div>

      <hr>

      <footer>
        <p>&copy; 2016 Company, Inc.</p>
      </footer>
    </div>
    <script>
      
        $(function () {
          
            $("#register input").blur(function(event) {
                var data = $(this).val();
                var name = $(this).attr('name')
                that = $(this);

                var postData = {data: data,name:name};

                if(name=="repassword"){
                   postData.password = $('input[name="password"]').val();
                }

                $.ajax({
                  url: './index.php?c=User&a=register_ajax',
                  type: 'POST',
                  dataType: 'json',
                  data: postData,
                })
                .done(function(res) {
                  console.log(res);
                  if(res.error==1){
                    that.parent().siblings('.info').addClass('red').html('<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>'+res.info);
                  }else{
                    that.parent().siblings('.info').removeClass('red').html('<span class="glyphicon glyphicon-ok" aria-hidden="true"></span>'+res.info);
                  }
                  if($('.glyphicon-ok').length==5){
                    $('#btn').removeAttr('disabled');
                  }else{

                  }
                })
                .fail(function() {
                  // alert("服务异常，请稍后再试");
                });
                
            });
        })

    </script>

  </body>
</html>
